package com.darcytech.debezium.core.pool;

import com.darcytech.debezium.core.kafka.connect.model.Config;
import com.darcytech.debezium.core.work.UserAndPassHelper;

public class ConnectorInfo {

    private final String group;

    private final String hostName;

    private final Integer port;

    String userName;

    String password;

    String userNameExpression;

    String passwordExpression;

    private final String tables;

    private final String dataBases;

    private final String groupSchemaTopic;

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setUserNameExpression(String userNameExpression) {
        this.userNameExpression = userNameExpression;
    }

    public void setPasswordExpression(String passwordExpression) {
        this.passwordExpression = passwordExpression;
    }

    public String getGroup() {
        return group;
    }

    public String getHostName() {
        return hostName;
    }

    public Integer getPort() {
        return port;
    }

    public String getUserName() {
        return userName;
    }

    public String getPassword() {
        return password;
    }

    public String getUserNameExpression() {
        return userNameExpression;
    }

    public String getPasswordExpression() {
        return passwordExpression;
    }

    public String getTables() {
        return tables;
    }

    public String getDataBases() {
        return dataBases;
    }

    public String getGroupSchemaTopic() {
        return groupSchemaTopic;
    }

    public String getConnectorName() {
        return getGroup() + "-" + getHostName() + "@" + getPort();
    }

    public ConnectorInfo(String group, String hostName, Integer port, String tables, String userName, String password,
                         String dataBases, String groupSchemaTopic) {
        this.group = group;
        this.hostName = hostName;
        this.port = port;
        this.userName = userName;
        this.userNameExpression = userName;
        this.password = password;
        this.passwordExpression = password;
        this.tables = tables;
        this.dataBases = dataBases;
        this.groupSchemaTopic = groupSchemaTopic;
    }

    public ConnectorInfo(Config config) {
        this(config.getDataBaseServerName(), config.getDataBaseHostName(), Integer.valueOf(config.getDataBasePort()),
                config.getTableIncludeList(), config.getDataBaseUser(), config.getDataBasePassword(), config.getDataBaseIncludeList(), config.getSchemaTopic());
    }

}
